////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012 Kentaro Sekimoto  All rights reserved.
////////////////////////////////////////////////////////////////////////////

#include <tinyhal.h>

#ifdef TEST_EVENTS
void TestEvents(void)
{
    char key[1];
    int i = 0;
#if defined(MB9BF568R)
    GPIO_PIN pin = (GPIO_PIN)0x34;
#else
    GPIO_PIN pin = (GPIO_PIN)0x34;
#endif
    BOOL state = TRUE;
    CPU_GPIO_EnableOutputPin(pin, state);
    while (true) {
        CPU_GPIO_SetPinState(pin, state);
        lcd_printf("Waiting key %d:", i);
        hal_printf("Waiting key %d:", i);
        UINT32 Events = Events_WaitForEvents(SYSTEM_EVENT_FLAG_COM_IN, 3000);
        if (Events & SYSTEM_EVENT_FLAG_COM_IN) {
            Events_Clear(SYSTEM_EVENT_FLAG_COM_IN);
            DebuggerPort_Read(HalSystemConfig.DebugTextPort, key, 1);
            lcd_printf("%c\r\n", key[0]);
            hal_printf("%c\r\n", key[0]);
        } else {
            lcd_printf("\r\n");
            hal_printf("\r\n");
        }
        state ^= 1;
        i++;
    }
}
#endif
